<template>
  <div></div>
</template>

<script setup lang="ts">
  import Store from 'electron-store'
  /* const store = new Store()
    store.set('name', 'kunkun')
    console.log(store.get('name'))
    console.log(store.path, 'path')
    console.log(store.store, 'store') */

  // ts
  type User = {
    id: number
    username: string
    age: number
    userType: string
    sort: number
  }
  type Data = {
    users: User[]
  }

  const store = new Store<Data>({
    // 文件夹名称
    cwd: 'db',
    // 文件名
    name: 'db',
    // 默认值
    defaults: { users: [] },
    // 数据加密
    encryptionKey: '123456'
  })

  /* const user = { id: 1, username: 'kunkun', age: 18, userType: 'user', sort: 10 }
    let users = store.get('users')
    users.push(user) */
  // store.set('users', users)

  // console.log(store.store)
  // 获取值
  let users = store.get('users')
  let username = store.get('users[0].username')
  let data = store.store
  let path = store.path

  // 设置值
  store.set('users', [...users, { id: 2, username: 'kunkun2', age: 18, userType: 'user', sort: 10 }])
  // store.set('articles', [{ id: 1, title: 'kunkun' }])

  // 在编辑器中打开存储文件
  // store.openInEditor()

  // 删除 users 字段
  // store.delete('users')

  // 删除所有值，重置为默认值
  // store.clear()
</script>

<style scoped></style>
